package com.heima.comment.controller;

import com.heima.comment.dto.CommentDto;
import com.heima.comment.dto.CommentLikeDto;
import com.heima.comment.dto.CommentRepaySaveDto;
import com.heima.comment.dto.CommentSaveDto;
import com.heima.comment.service.IApCommentService;
import com.heima.comment.service.ICommentRepayService;
import com.heima.common.dto.ResponseResult;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Author WSJ
 * @Date 2022-03-29-9:34
 * @Version 1.0 （版本号）
 */
@RestController
@RequestMapping("/api/v1/comment")
@Api(tags = "文章评论模块")
public class ApCommentController {
    @Autowired
    private IApCommentService commentService;

    /**
     * 保存评论
     * @param dto
     * @return
     */
    @PostMapping("/save")
    public ResponseResult save(@RequestBody CommentSaveDto dto) {
        return commentService.save(dto);
    }

    /**
     * 分页查询评论列表
     * @param dto
     * @return
     */
    @PostMapping("/load")
    public ResponseResult load(@RequestBody CommentDto dto) {
        return commentService.load(dto);
    }

    /**
     * 点赞、取消点赞
     * @param dto
     * @return
     */
    @PostMapping("/like")
    public ResponseResult like(@RequestBody CommentLikeDto dto) {
        return commentService.like(dto);
    }

    /**
     * 查看评论列表
     * @param dto
     * @return
     */
    @PostMapping("/list")
    public ResponseResult list(@RequestBody CommentDto dto) {
        return commentService.list(dto);
    }

    @Autowired
    private ICommentRepayService commentRepayService;

    /**
     * 回复评论
     * @param dto
     * @return
     */
    @PostMapping("/manage/comment_repay")
    public ResponseResult commentRepay(@RequestBody CommentRepaySaveDto dto) {
        return commentRepayService.save(dto);
    }

    /**
     * 删除评论回复
     * @param commentRepayId
     * @return
     */
    @DeleteMapping("/manage/del_comment_repay/{commentRepayId}")
    public ResponseResult delete(@PathVariable("commentRepayId") String commentRepayId) {
        return commentRepayService.delete(commentRepayId);
    }

    /**
     * 评论点赞
     * @param dto
     * @return
     */
    @PostMapping("/manage/like")
    public ResponseResult manageLike(@RequestBody CommentLikeDto dto) {
        return commentService.like(dto);
    }

    /**
     * 删除评论
     * @param commentId
     * @return
     */
    @DeleteMapping("/manage/del_comment_repay/{commentId}")
    public ResponseResult deleteComment(@PathVariable("commentId")String commentId) {
        return commentService.delete(commentId);
    }
}
